package github.sf.fw.utils;

import org.springframework.beans.BeanUtils;

import java.util.Collection;
import java.util.Date;
import java.util.Optional;

/**
 * 通用工具
 */
public class JKit {
    public static boolean emptyCollection(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static void copyProps(Object src, Object target) {
        BeanUtils.copyProperties(src, target);
    }

    public static void copyProps(Object src, Object target, String... ignoreProps) {
        BeanUtils.copyProperties(src, target, ignoreProps);
    }

    public static <T> Optional<T> wrap(T obj) {
        return Optional.ofNullable(obj);
    }

    public static Date systemDate() {
        return new Date();
    }

    public static long snowflakeId() {
        return Ids.getSnowflake().nextId();
    }

    public static long string2Long(String idStr) {
        return Long.parseLong(idStr);
    }
}
